<?php
$id = 0;
$code = NULL;
if (wgGet::isValue('edit')) {
	$id = (int) wgGet::getValue('edit');
	if (IchatGroupsModel::validateUserGroup($id)) {
		$group = IchatGroupsModel::getOneUserData($id, moduleUsers::getId());
		$title = 'Edit "'.$group->getName().'"';
		$code = '<p>Your form API code is: <strong style="color:red;">'.$group->getCode().'</strong></p>';
	}
	else $id = 0;
}
if (!(bool) $id) {
	$group = new IchatGroupsModel();
	$title = 'Create new form';
}

?><a name="editForm"></a>
<form action="?from=<?php echo (int) wgGet::getValue('from'); ?>" method="post" class="form">
	<h2><?php echo $title; ?></h2>
	<fieldset>
		<p>
			<label for="ifname" class="mandatory">Form name:</label>
			<input name="ifname" id="ifname" type="text" value="<?php echo $group->getName(); ?>" title="Name of your group (should be name of the app, etc ...)" />
		</p><?php echo $code; ?>
	</fieldset>
	<fieldset>
		<p>
			<input name="edit" type="hidden" value="<?php echo (int) $id; ?>" />
			<button name="reset" type="reset">Reset</button>
			<!--<button name="applyGroup" type="submit">Apply</button>-->
			<button name="submitGroup" type="submit">Save</button>
		</p>
	</fieldset>
</form>